package com.yzt.zhuju.arouter;

import android.content.Intent;
import android.text.TextUtils;
import android.util.Log;

import com.alibaba.android.arouter.core.LogisticsCenter;
import com.alibaba.android.arouter.facade.Postcard;
import com.alibaba.android.arouter.launcher.ARouter;
import com.yzt.zhuju.RXingUtils;

import java.io.Serializable;

/**
 * author : bob
 * date   : 2022/11/29
 * desc   :
 */
public class RouterMain {

    //主页
    public static final String ACTIVITY_MAIN = "/main/MainActivity";

    //URL
    public static final String ACTIVITY_APP_WEB_VIEW = "/webs/AppWebViewActivity";

    //透明webview
    public static final String ACTIVITY_APP_TRANS_WEB_VIEW = "/webs/TransWebViewActivity";

    /**
     * 跳转主页
     */
    public static void MainActivity(boolean isJumpMode2) {
        //   if (isSelectSex(isJumpMode2)) {
        ARouter.getInstance().build(ACTIVITY_MAIN).navigation();
        //   }
    }

    /**
     * 跳转主页
     */
    public static void MainActivity() {
        ARouter.getInstance().build(ACTIVITY_MAIN).navigation();
    }

    public static boolean isSelectSex() {
        if (RXingUtils.getLoginAccount() != null) {
            if (!RXingUtils.getLoginAccount().isEdited()) {
                RouterAccount.RegisterChooseGenderActivity();
                return false;
            }
        }
        return true;
    }

    /**
     * 跳转主页
     */
    public static void MainActivity(Serializable msg) {
        if (isSelectSex()) {
            ARouter.getInstance().build(ACTIVITY_MAIN).withSerializable("AgoraCallMsg", msg).navigation();
        }
    }

    /**
     * 跳转主页
     */
    public static void MainActivity(String roomId) {
        if (isSelectSex()) {
            ARouter.getInstance().build(ACTIVITY_MAIN).withString("roomId", roomId).navigation();
        }
    }

    /**
     * 跳转主页 - 并且跳转到通话页面
     */
    public static void MainActivityToCallChat() {
        ARouter.getInstance().build(ACTIVITY_MAIN).withBoolean("jumpCallChat", true).navigation();
    }

    public static String getMainActivityClassAllPathName() {
        Postcard build = ARouter.getInstance().build(ACTIVITY_MAIN);
        LogisticsCenter.completion(build);
        if (build.getDestination() != null) {
            //p.getDestination()是一个class，即路径指向的activity
            return build.getDestination().getName();
        }
        return "MainActivity";
    }

    public static void goToWeb(String url) {
        Log.i("gz-webapi", "gotoweb==" + url);
        goToWeb(url, "");
    }

    public static void goToWeb(String url, String headGson) {
        if (TextUtils.isEmpty(url)) {
            return;
        }

        ARouter.getInstance().build(ACTIVITY_APP_WEB_VIEW)
                .greenChannel()
                .withString("mUrl", url)
                .withString("mHeadGson", headGson)
                .withFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
                .navigation();
    }

    public static void goToTransWeb(String url, String headGson) {
        if (TextUtils.isEmpty(url)) {
            return;
        }
        ARouter.getInstance().build(ACTIVITY_APP_TRANS_WEB_VIEW)
                .greenChannel()
                .withString("mUrl", url)
                .withString("mHeadGson", headGson)
                .withFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
                .navigation();
    }
}
